package com.qf.Service.Impl;



import com.qf.Dao.Impl.ProductDaoImpl;
import com.qf.Dao.ProductDao;
import com.qf.Entity.Page;
import com.qf.Entity.Product;
import com.qf.Service.ProductService;
import com.qf.Util.DruidUtil;

import java.util.List;

/*2021/10/9*/public class ProductServiceImpl implements ProductService {
    ProductDao productDao=new ProductDaoImpl();

    @Override
    public List<Product> selectPage(Page page) {
        Long aLong = productDao.selectCount();
        page.setTotalCount(aLong);
        DruidUtil.close();
        return productDao.selectPage(page);
    }

    @Override
    public Integer insertProduct(Product product) {
        Integer result=0;
        try {
            DruidUtil.begin();
            result = productDao.insertProduct(product);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Integer updateProduct(Product product) {

        Integer result=0;
        try {
            DruidUtil.begin();
            result = productDao.updateProduct(product);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Integer deleteProduct(Integer pId) {
        Integer result=0;
        try {
            DruidUtil.begin();
            result = productDao.deleteProduct(pId);
            DruidUtil.commit();
        } catch (Exception e) {
            e.printStackTrace();
            DruidUtil.rollback();
        } finally {
            DruidUtil.close();
        }
        return result;
    }

    @Override
    public Product selectBypId(Integer pId) {
        DruidUtil.close();
        return productDao.selectBypId(pId);
    }
}
